/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Fariz
 */
import java.util.*;
import javax.swing.JOptionPane;

public class soal47 {

    public int number;
    int j = 0;
    int i = 10;
    private ArrayList<Integer> list = new ArrayList<Integer>();

    public soal47(int maxNum) {
        number = maxNum;
    }

    ArrayList<Integer> isPalindrome() {

        while (j != number) {
            Integer in = new Integer(i);
            String number = in.toString();
            int index1 = 0;
            int index2 = number.length() - 1;
            char x = number.charAt(index1);
            char y = number.charAt(index2);

            while (index2 - index1 >= 0) {
                if (x != y) {
                    break;
                }
                if (index2 - index1 == 0 || index2 - index1 == 1) {
                    if (isPrime(i)) {
                        list.add(i);
                        j = j + 1;
                    }
                }
                index1++;
                index2--;
                x = number.charAt(index1);
                y = number.charAt(index2);
            }
            i = i + 1;
        }
        return list;
    }

    static boolean isPrime(int number) {
        boolean isPrime = false;
        int i = (int) Math.ceil(Math.sqrt(number));
        while (i > 1) {
            if ((number != i) && (number % i == 0)) {
                isPrime = false;
                break;
            } else if (!isPrime) {
                isPrime = true;
            }
            --i;
        }
        return isPrime;
    }

    public static void main(String[] args) {
        int n;
        String angka = JOptionPane.showInputDialog("Masukkan nilai n: ");
        n = Integer.parseInt(angka);
        ArrayList<Integer> palindromes = new ArrayList<Integer>();
        soal47 pp = new soal47(n);
        palindromes = pp.isPalindrome();
        Iterator<Integer> iterasi = palindromes.iterator();
        while (iterasi.hasNext()) {
            int current = iterasi.next();
            if (isPrime(current)) {
                System.out.println(current);
            }

        }

    }
}
